object t5 {
  def generatePascalsTriangle(rows: Int): List[List[Int]] = {
    val triangle = Array.fill(rows)(Array.fill(rows)(0))

    for (row <- 0 until rows) {
      triangle(row)(0) = 1
      triangle(row)(row) = 1
      for (col <- 1 until row) {
        triangle(row)(col) = triangle(row - 1)(col - 1) + triangle(row - 1)(col)
      }
    }
    triangle.take(rows).map(_.take(rows).filter(_ != 0).toList).toList
  }

  // 主函数，测试所有功能
  def main(args: Array[String]): Unit = {
    val pascalTriangle = generatePascalsTriangle(5)
    println("Pascal's Triangle (5 rows):")
    pascalTriangle.foreach(println)
  }
}
